package com.tywj.panda.travel.api

import androidx.collection.ArrayMap
import com.tywj.panda.customer.common.api.CommonApi
import com.tywj.panda.customer.common.manager.AuthorityManager
import com.tywj.panda.customer.common.tool.HttpTool
import com.tywj.lib.net.retrofit.request.GetRequest
import com.tywj.lib.net.retrofit.request.PostRequest

/**
 * @desc 行程组件网络请求接口
 * @author June Yang
 * @date 2019/12/12
 */
object TravelApi {

    //服务订单
    private const val TRAVEL_LIST_ORDER = "serviceOrder/all"

    //行程分页(按天查询)
    private var TRAVEL_ORDER_LIST = CommonApi.API_TICKET_URL + "ticket/orderinfo/search/trip"

    //历史行程分页(按天查询)
    private var TRAVEL_ORDER_LIST_HISTORY = CommonApi.API_TICKET_URL + "ticket/orderinfo/search/trip/his"


    //行程查询 POST /orderinfo/search/trip
    private var TRAVEL_LIST = CommonApi.API_TICKET_URL + "orderinfo/search/trip"

    //验票服务
    private var TRAVEL_CHECK_TICKETS = CommonApi.API_TICKET_URL + "ticket/inspect/done"

    //退票
    private var TRAVEL_REFUND_TICKETS = CommonApi.API_TICKET_URL + "ticket/refund/ticket"

    fun listTravel(): GetRequest = HttpTool.get(TRAVEL_ORDER_LIST)

    fun listTravelHistory(): GetRequest = HttpTool.get(TRAVEL_ORDER_LIST_HISTORY)


    fun listTravelParams(
        lineDate: String = ""
    ): ArrayMap<String, String> {
        val map = ArrayMap<String, String>()
        //在分页时加载更多
        if (lineDate.isNotEmpty()) {
            map["line_Date"] = lineDate
        }
        map["uid"] = AuthorityManager.uid
        return map
    }


    /**
     * 车票中心-验票服务
     */
    fun checkTickets(driverCode: String, number: Int, ticketCode: String, goodsNo: String): PostRequest {
        return HttpTool.post(TRAVEL_CHECK_TICKETS)
            .param("driver_code", driverCode)
            .param("number", number)
            .param("ticket_code", ticketCode)
            .param("goods_no", goodsNo)
    }

    /**
     * 车票中心-退票
     * @param remark 备注
     * @param ticketNo 车票号
     * @param number 数量
     * @param svrFee 手续费
     * @param refundFee 退款金额
     */
    fun refundTickets(
        remark: String = "没有备注",
        number: Int,
        ticketNo: String,
        svrFee: Int,
        refundFee: Int
    ): PostRequest {
        return HttpTool.post(TRAVEL_REFUND_TICKETS)
            .param("remark", remark)
            .param("num", number)
            .param("ticke_no", ticketNo)
            .param("svr_fee", svrFee)
            .param("refund_fee", refundFee)
    }
}